package stu.day19_day24.day23;

import java.util.Arrays;
import java.util.Scanner;


public class hw3 {


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String[] str = sc.nextLine().split("[,]");

        int[][] arr = new int[str.length][2];
        for (int i=0;i<str.length;i++){
            arr[i][0] =Integer.parseInt( str[i].split("[:]")[0]);
            arr[i][1] =Integer.parseInt( str[i].split("[:]")[1]);
        }

        Arrays.sort(arr,((o1, o2) -> {
            if(o1[1]!=o2[1]){
                return o1[1]-o2[1];
            }else {
                return o2[0]-o1[0];
            }
        }));

        int num = Math.max(arr[0][0],arr[0][1]);

        for(int i=1;i<arr.length;i++){
            if(num+arr[i][0]>=arr[i][1]){
                num += arr[i][0];
            }else {
                num = arr[i][1];
            }
        }

        System.out.println(num);
    }


}
